package cn.itcast.contorller;

import cn.itcast.domain.Accounts;
import cn.itcast.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private AccountService accountService;

//    查询全部
    @RequestMapping(value = "/findall")
    public Object findAll()throws Exception{
        List<Accounts> all = accountService.findAll();
        System.out.println(all);
        return all;
    }





    @RequestMapping(value = "/findByid/{id}")
    public Object findById(@PathVariable String id)throws Exception{
        int i = Integer.parseInt(id);
        Accounts byId = accountService.findById(i);
        return byId;
    }

    @RequestMapping(value = "/add" ,method = RequestMethod.POST)
    public Object add(@RequestBody Accounts accounts)throws Exception{

       accountService.add(accounts);
        return true;
    }


    @RequestMapping(value = "/update" ,method = RequestMethod.PUT)
    public Object update(@RequestBody Accounts accounts)throws Exception{

        accountService.update(accounts);
        return true;
    }

    @RequestMapping(value = "/delete/{id}" ,method = RequestMethod.DELETE)
    public Object deledt(@PathVariable String id)throws Exception{
        int i = Integer.parseInt(id);
        accountService.delete(i);
        return true;
    }
}
